import { axios } from '@/utils/request'
import { getAction, postAction, getFileAction } from '@/api/manage'

/**
 * 根据订单ID获取设计文件
 * @param {string} orderId - 订单ID
 */
export function getDesignFileByOrderId(orderId) {
  return axios({
    url: '/oms/designFile/getByOrderId',
    method: 'get',
    params: { orderId }
  })
}

/**
 * 验证汇总单文件
 * @param params 表单数据
 * @returns {Promise}
 */
export function validateSummaryFile(params) {
  return axios({
    url: '/oms/designFile/validateSummaryFile',
    method: 'post',
    data: params,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 上传汇总单文件
 * @param {FormData} formData - 包含文件和订单ID的表单数据
 */
export function uploadSummaryFile(formData) {
  return axios({
    url: '/oms/designFile/uploadSummaryFile',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 处理汇总单解析结果
 * @param params 表单数据
 * @returns {Promise}
 */
export function processSummaryFileResult(params) {
  return axios({
    url: '/oms/designFile/processSummaryFileResult',
    method: 'post',
    data: params,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 上传优化单文件
 * @param {FormData} formData - 包含文件和订单ID的表单数据
 */
export function uploadOptimizationFile(formData) {
  return axios({
    url: '/oms/designFile/uploadOptimizationFile',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 获取最近上传的设计文件
 * @param {number} limit - 限制返回的记录数
 */
export function getRecentFiles(limit = 10) {
  return axios({
    url: '/oms/designFile/getRecentFiles',
    method: 'get',
    params: { limit }
  })
}

/**
 * 上传优化单
 * @param params 表单数据
 * @returns {Promise}
 */
export function uploadOptimization(params) {
  return axios({
    url: '/oms/designFile/uploadOptimization',
    method: 'post',
    data: params,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 获取型材切割方案详情
 * @param orderId 订单ID
 * @param profileCode 型材编码
 * @returns {Promise}
 */
export function getCutDetails(orderId, profileCode) {
  return axios({
    url: '/oms/designFile/getCutDetails',
    method: 'get',
    params: {
      orderId: orderId,
      profileCode: profileCode
    }
  })
}

/**
 * 获取订单的型材清单和配件清单
 * @param orderId 订单ID
 * @returns {Promise}
 */
export function getOrderMaterialsAndAccessories(orderId) {
  return axios({
    url: '/oms/productSalesOrder/getOrderMaterialsAndAccessories',
    method: 'get',
    params: {
      orderId: orderId
    }
  })
}

/**
 * 获取设计订单详情
 * @param orderId 订单ID
 * @returns {Promise}
 */
export function getDesignOrderDetail(orderId) {
  return axios({
    url: '/oms/productSalesOrder/getDesignOrderDetail',
    method: 'get',
    params: {
      orderId: orderId
    }
  })
} 